package com.cxl.autocode.data;

import java.lang.reflect.Field;
import java.util.HashMap;
import java.util.Map;

import com.cxl.test.Good;

public class BeanInfo {
	
	public String listPage="apps/template/list.jsp.ftl";
	public String addPage="apps/template/input.jsp.ftl";
	public String updatePage="apps/template/update.jsp.ftl";
	
	public String path;
	
	
	
	//需要生成的对象
	public Object obj;
	
	//对象名称
	public String objName;
	
	//字段信息
	public Map<String,String> fieldMap;
	
	public BeanInfo(Object obj) {
		super();
		this.obj = obj;
		parser();
		
	}

	public Object getObj() {
		return obj;
	}

	public void setObj(Object obj) {
		this.obj = obj;
	}

	public String getObjName() {
		return objName;
	}

	public void setObjName(String objName) {
		this.objName = objName;
	}

	public Map<String, String> getFieldMap() {
		return fieldMap;
	}

	public void setFieldMap(Map<String, String> fieldMap) {
		this.fieldMap = fieldMap;
	}
	
	
	public String getPath() {
		if(path!=null||"".equals(path))
			path+="/";
		return path==null?"":path;
	}

	public void setPath(String path) {
		this.path = path;
	}

	/**
	 * 初始化
	 */
	public void parser()
	{
		Field[] fields =  getObj().getClass().getDeclaredFields();
		fieldMap=new HashMap<String, String>();
		for(int i=0;i<fields.length;i++)
		{
			fieldMap.put(fields[i].getName(),fields[i].getName());
		}
		
		String pathArray[]=getObj().getClass().getName().split("\\.");
		int arraySize=pathArray.length;
		setObjName(pathArray[arraySize-1].toLowerCase());
	}
	
	public static void main(String[] args) {
		
		
		BeanInfo beaninfo=new BeanInfo(new Good());
		 beaninfo.parser();
	}
	
	
	

}
